﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using SAPPDI.Entitys;
using TestImpresion.Clases;

namespace TestImpresion.Controles
{
    public partial class ComprarPor : UserControl
    {
        private readonly DependencyProperty _datasourceProperty =
  DependencyProperty.Register("Datasource", typeof(ComparPorFormulario), typeof(ComprarPor), new PropertyMetadata(new ComparPorFormulario()));

        [System.ComponentModel.Category("User properties")]
        [System.ComponentModel.Description("User Datasource")]
        public ComparPorFormulario Datasource
        {
            get { return (ComparPorFormulario)GetValue(_datasourceProperty); }
            set { SetValue(_datasourceProperty, value); }
        }

        /// <summary>
        /// Delegado
        /// </summary>
        /// <param name="sender">Objeto que genera el evento</param>
        /// <param name="e">Parametros del evento <see cref="InsertosEventArgs"/></param>
        public delegate void CalculoEventHandler(object sender, EventArgs e);
        /// <summary>
        /// Evento que se dispara al encontrar el folio buscado.
        /// </summary>
        public event CalculoEventHandler CalculoEvent;

        public ComprarPor()
        {
            InitializeComponent();
            this.LayoutRoot.DataContext = this.Datasource;
        }

        public void SetCostos(ComparPorFormulario formulario)
        {
            this.Datasource = formulario;
            this.LayoutRoot.DataContext = this.Datasource;
        }

        public ComparPorFormulario GetValores()
        {
            double impresion;
            double acabados;
           var existimpresion= double.TryParse(this.txtCostoImpresion.Text, out impresion);
            var existacabados= double.TryParse(this.txtCostoPliego.Text, out acabados);
            var regreso = new ComparPorFormulario()
                {
                    PliegoSeleccionado = DinamicId.PliegoSeleccionado,
                    CostoImpresion = existimpresion ? impresion : 0.0,
                    CostoPliegos = existacabados ? acabados : 0.0
                };
            return regreso;
        }

        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            if (this.CalculoEvent != null)
            {
                this.CalculoEvent(this, new EventArgs());                
            }
        }
    }
}
